<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>

    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card class="box-card">
      <el-row>
        <!-- 请输入内容 -->
        <el-col :span="8">
            <el-input placeholder="请输入内容" clearable v-model="queryinfo" class="input-with-select" style="width:300px" @clear="getOrdersList">
                <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
            </el-input>
          
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table :data="orderList" style="width: 100%;" border>
        <!-- 索引行 -->
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="500px"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" ></el-table-column>
        <el-table-column prop="order_pay" label="是否付款" >
          <el-tag type="success" v-if="orderList.order_pay == '1'">已付款</el-tag>
          <el-tag type="danger" v-else>未付款</el-tag>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" ></el-table-column>
        <el-table-column prop="create_time" label="下单时间" >
          <template slot-scope="scope">
            {{scope.row.create_time | dateFormat}}
          </template>
        </el-table-column>
        <!-- 操作区域 -->
        <el-table-column prop="order_number" label="操作" width="120px">
          <template slot-scope='scope'>
            <el-button type="primary" size="mini" icon="el-icon-edit" @click="editOrders(scope.row)"></el-button>
            <el-button type="success" size="mini" icon="el-icon-location" @click="locationTimeline(scope.row)"></el-button>
          </template>
        </el-table-column>
      
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pagenum"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
     
    </el-card>
    <!-- 当点击快递按钮时，显示弹窗时间线 -->
    <el-dialog
    title="物流信息" :visible.sync="timelineVisible" width="50%">
      <!-- 时间轴 -->
      <el-timeline>
        <!-- :timestamp="item.time" 时间 item.context 内容 -->
        <el-timeline-item
          v-for="(item, index) in timelineData"
          :key="index"
          :timestamp="item.time">
          {{item.context}}
        </el-timeline-item>
      </el-timeline>

    </el-dialog>
    <!-- 当点击编辑信息按钮时，显示弹窗  -->
    <el-dialog
      title="编辑信息"
      :visible.sync="editOrdersVisible"
      width="50%"
      @close="editOrdersClosed">
      <!-- 表单信息 -->
      <el-form label-width='100px' :model="editOrdersForm" :rules="editOrdersFormRules" ref="editOrdersFormRef">
        <el-form-item label="省市区/县" prop="address1">
          <!-- 级联选择器 -->
          <el-cascader
   
            :options="cityData"
            v-model="editOrdersForm.address1"
            :props="editOrdersProps"
            clearable>
          </el-cascader>
            
       
        </el-form-item>
        <!--  -->
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="editOrdersForm.address2"></el-input>
        </el-form-item>
        
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editOrdersVisible = false">取 消</el-button>
        <el-button type="primary" @click="editOrdersVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
// 导入城市列表数据
import cityData from "./citydata.js";
export default {
  
  data(){
    return{
      // 页码
      pagenum:1,
      pagesize:5,
      // 总的信息条数
      total:0,
      // 搜索框信息
      queryinfo:"",
      // 订单数据
      orderList:[],
      // 点击时间轴，是否显示时间轴
      timelineVisible:false,
      // 时间轴显示项目
      timelineData:[],
      // 点击编辑按钮，是否显示编辑对话框
      editOrdersVisible:false,
      // 编辑信息列表
      editOrdersForm:{
        address1:[],
        address2:""
      },
      // 编辑信息验证规则
      editOrdersFormRules:{
        address1: [
          { required: true, message: '请选择省市区县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请填写详细地址', trigger: 'blur' }
        ]
      },
      // 城市列表数据
      cityData:cityData,
      // 
      editOrdersProps:{
        expandTrigger: 'hover' 
      }
     
      
    }
  },
  methods:{
    // 获取订单数据
    async getOrdersList(){
      // 获取数据
      const {data:res} = await  this.$http.get("orders",{
        params:{
          pagenum:this.pagenum,
          pagesize:this.pagesize,
          query:this.queryinfo
        }
      });
      console.log(res);
      // 判断返回来的状态码
      if(res.meta.status !== 200){
        return this.$message.error("数据请求失败")
      }
      // 将请求回来的数据保存
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    // 当页码数量改变时
    handleSizeChange(val){
      //
      console.log(val);
      // 将当前页数量重新赋值
      this.pagesize= val
      // 重新获取数据
      this.getOrdersList()
      
    },
    // 当页码当前页码改变时
    handleCurrentChange(val){
      //重新赋值当前页码
      this.pagenum = val
      // 重新获取数据
      this.getOrdersList()
    },
    // 当点击时间轴按钮时显示时间轴
    async locationTimeline(row){
      console.log(row);
      
      // 向服务器获取物流信息数据
      const {data:res} = await this.$http.get("/kuaidi/804909574412544580")
      // 判断是
      console.log(res);
      // 判断服务器返回的状态
      if(res.meta.status !== 200){
        return this.$message("数据获取失败")
      }
      // 将获取的数据进行保存
      this.timelineData = res.data
      
      this.timelineVisible = true
    },
    // 当点击编辑订单信息按钮时
    editOrders(row){
      this.editOrdersVisible = true
    },
    // 当点击关闭编辑订单信息对话窗按钮
    editOrdersClosed(){
      this.$refs.editOrdersFormRef.resetFields()
    },
    // 当选择城市信息时触发事件
    cityDataChange(){

    }
    
  },
  created(){
    // 
    this.getOrdersList()
    

  }

}
</script>

<style>

</style>